package com.leetao.dingtalk;

import com.leetao.dingtalk.core.config.DingTalkProperties;
import com.leetao.dingtalk.core.manager.DingTalkTokenManager;
import com.leetao.dingtalk.core.service.DingTalkAuthService;
import com.leetao.dingtalk.core.service.DingTalkNotificationService;
import com.leetao.dingtalk.core.service.impl.DingTalkAuthServiceImpl;
import com.leetao.dingtalk.core.service.impl.DingTalkNotificationServiceImpl;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import javax.annotation.Resource;

/**
 * 钉钉自动配置
 * @author 菅江晖
 * @date 2021/5/24 - 10:33
 */
@SpringBootConfiguration
@ConditionalOnProperty(prefix = "jjh.ding-talk",value = "enable",havingValue = "true")
@EnableConfigurationProperties(DingTalkProperties.class)
@EnableScheduling
public class DingTalkAutoConfiguration {

    @Resource
    DingTalkProperties dingTalkProperties;

    @Bean
    public DingTalkAuthService dingTalkAuthService(){
        return new DingTalkAuthServiceImpl(dingTalkProperties);
    }


    @Bean
    public DingTalkTokenManager dingTalkTokenManager() {
        return new DingTalkTokenManager(dingTalkAuthService());
    }

    @Bean
    public DingTalkNotificationService dingTalkNotificationService() {
        return new DingTalkNotificationServiceImpl(dingTalkProperties,dingTalkTokenManager());
    }

}
